package com.ware.controller.admin;

import com.ware.controller.BaseController;
import com.ware.jfinal.plugin.shiro.SH;
import com.ware.jfinal.plugin.shiro.ShiroRealm.ShiroUser;


public class IndexController extends BaseController{

	public void index() {
		this.render("login.ftl");
	}
	public void login(){
		if("post".equalsIgnoreCase(this.getRequest().getMethod())){	
			String userName = this.getPara("user_name","");
			String password = this.getPara("password","");		
			String result = SH.login(userName, password, false);
			ShiroUser user = null;
			if(result.equalsIgnoreCase("success")){
				user = (ShiroUser)SH.getSubject().getPrincipal();
				this.setAttr("user", user);
				this.setAttr("isLogin", true);
				this.render("index.ftl");
			}else{
				this.setAttr("error", "用户名或密码不正确");
				this.render("login.ftl");
			}
		}else{						
			this.render("login.ftl");
		}		
	}
	
	public void logout(){
		SH.logout();
		this.redirect("/login");
	}
}
